/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package _4_Mapper;

import _3_Object.LoginObject;
import _5_DB.ConnectDB;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Lc.Danh
 */
public class LoginMapper {
    public static int login(LoginObject o)
    {
        try{
            
            ConnectDB db = new ConnectDB();
            Connection con = db.getConnection();
            
            CallableStatement proc = con.prepareCall("{ call procDangNhap(?, ?) }");          //tên procedure và tham số
            
            proc.setString(1, o.getUsername());      //tham số 1
            proc.setString(2, o.getPassword());          //tham số 2
            //doc ra thi can resultset, khong thi executeNonQuery(cai tra ve kieu Int)
            ResultSet rs = proc.executeQuery();                             //Trả về result set
            if (rs.next())
            {
                o.setuID(rs.getInt("uID"));
                o.setAvatar(rs.getString("avatar"));
            }
            con.close();
        } 
        catch(SQLException e)
        {
            System.out.println("Loi: "+e.getMessage());
        }
        
        return o.getuID();
    }
    
}
